<template>
  <div id='tabControl' class='tabControl'>
    <div v-for="(item,index) in titles" :key="index" class="tabcontrol-item" @click="itemClick(index)"
      :class="{active:index===currentIndex}">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'tabControl',
    props: { // 父辈向子辈传参

      titles: {
        type: Array,
        default () {
          return []
        }
      }
    },
    components: { // 组件的引用

    },
    data() {
      return {
        currentIndex: 0
      }
    },
    methods: { // 方法
      itemClick(index) {
        this.currentIndex = index
        this.$emit('tabclick', index)
      }
    },
    created() { // 实例被创建之后执行代码

    },
    computed: { // 计算属性

    },
    mounted() { // 页面进入时加载内容

    },
    watch: { // 监测变化

    }
  }

</script>
<style scoped>
  .tabControl {
    display: flex;
    text-align: center;
    font-size: 15px;
    height: 40px;
    line-height: 40px;
    background: white;
  }

  .tabcontrol-item {
    flex: 1;

  }

  .active {
    color: var(--color-high-text);

  }

  .active span {
    border-bottom: 3px solid var(--color-high-text);
  }

  .tabcontrol-item span {
    padding: 5px;
  }

</style>
